home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995 February: Tool Chest / Dev.CD Feb 95 / Dev.CD Feb 95.toast / Sample Code / Newton Sample Code 1.2 / Views / Size Doesn't Matter-2 / Size Doesn't Matter.π.text < prev    next >
Encoding:
Text File  |  1994-02-28  |  4.1 KB  |  123 lines  |  [TEXT/MPS ]

  1.  
  2. // ---- End Project Data ----
  3.  
  4.  
  5. // ---- File Size Doesn't Matter.t ----
  6.  
  7. // Before Script for "ResizeSampleApp"
  8. // Copyright 1993-1994 Apple Computer, Inc. All rights reserved.
  9.  
  10. ResizeSampleApp :=
  11.    {title: "Resize Sample",
  12.     viewBounds: {top: 0, left: 0, right: 240, bottom: 336},
  13.     viewSetupFormScript:
  14.       func()
  15.       begin
  16.          local a := GetAppParams();
  17.          self.viewBounds := RelBounds(a.appAreaLeft, a.appAreaTop, a.appAreaWidth, a.appAreaHeight);
  18.       end,
  19.     _proto: protoApp,
  20.     debug: "ResizeSampleApp"
  21.    };
  22.  
  23. sizeableView := /* child of ResizeSampleApp */
  24.    {viewFlags: 513,
  25.     viewFormat: 337,
  26.     viewBounds: {left: 67, top: 83, right: 169, bottom: 161},
  27.     viewClickScript:
  28.       func(unit)
  29.       begin
  30.          local r, newR, newB, newBounds;  // used inside loop
  31.       
  32.          // deltas keep track of how close the tap point is to the corner.
  33.          local deltaX := :GlobalBox().right - GetPoint(firstX, unit);
  34.          local deltaY := :GlobalBox().bottom - GetPoint(firstY, unit);
  35.       
  36.          // if we're near the lower right hand corner, resize the view.
  37.          // note we use ABS.  Because of "sloppy clicking" it's possible
  38.          // for this view's viewClickScript to get called even when
  39.          // the tap is technically outside the bounds, and it seems like
  40.          // a good idea to let these taps resize the view too.
  41.       
  42.          if ABS(deltaX) < 10 and ABS(deltaY) < 10 then
  43.          begin
  44.             InkOff(unit);
  45.       
  46.             // make a rectangle for the drag animation
  47.             r := MakeShape(viewBounds);
  48.             :Parent():DrawShape(r, XORRectStyle);   // draw frame
  49.             newBounds := Clone(viewBounds);
  50.       
  51.             // loop until stroke is finished
  52.             while not StrokeDone(unit) do
  53.             begin
  54.                // track the pen, and if it's moved, update the wire frame
  55.                newR := GetPoint(finalX, unit) + deltaX;
  56.                newB := GetPoint(finalY, unit) + deltaY;
  57.                if newR <> newBounds.right or newB <> newBounds.bottom then
  58.                begin
  59.                   newBounds.right := newR;
  60.                   newBounds.bottom := newB;
  61.                   :Parent():DrawShape(r, XORRectStyle);   // undraw old frame
  62.                   ScaleShape(r, nil, newBounds);
  63.                   :Parent():DrawShape(r, XORRectStyle);   // draw frame
  64.                   Sleep(1);   // short delay, maybe save batteries?
  65.                end;
  66.              end;
  67.             :Parent():DrawShape(r, XORRectStyle);   // undraw old frame
  68.       
  69.             newBounds.right := GetPoint(finalX, unit) + deltaX;
  70.             newBounds.bottom := GetPoint(finalY, unit) + deltaY;
  71.             // just setting viewBounds won't work, use SyncView or SetValue.
  72.             SetValue(self, 'viewBounds, newBounds);   // call viewChangedScript
  73.          end
  74.          else
  75.          begin
  76.             // just for fun, drag the view if the tap is anywhere else
  77.             :Drag(unit, nil);
  78.             // clean up viewBounds after Drag munges them.
  79.             // this is only valid for parent top/left justified views!
  80.             local b := :GlobalBox();
  81.             local p := :Parent():GlobalBox();
  82.             b.top := b.top - p.top;
  83.             b.left := b.left - p.left;
  84.             b.bottom := b.bottom - p.top;
  85.             b.right := b.right - p.left;
  86.             SetValue(self, 'viewBounds, b); // call viewChangedScript
  87.          end;
  88.          TRUE;   // we've handled the tap
  89.       end,
  90.     viewSetupFormScript:
  91.       func()
  92.       begin
  93.          // need writeable copy of viewBounds for viewClickScript
  94.          If IsReadOnly(viewBounds) then
  95.             self.viewBounds := Clone(viewBounds);
  96.       end,
  97.     XORRectStyle:
  98.       // used in viewClickScript for animating frame during resize.
  99.       
  100.       {transferMode: modeXor, penSize: 1, penPattern: vfGray},
  101.     viewclass: 74,
  102.     debug: "sizeableView"
  103.    };
  104.  
  105.  
  106.  
  107. _view000 := /* child of ResizeSampleApp */
  108.    {text: "Drag lower right corner to change size.",
  109.     viewBounds: {top: -40, left: 0, right: 0, bottom: -20},
  110.     viewJustify: 8388790
  111.     ,
  112.     _proto: protoStaticText
  113.    };
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121. // ---- Beginning of section for non used Layout files ----
  122.  
  123. // End of output